package com.exer;

import org.junit.Test;

/**
 * 对字符串中字符进行自然顺序排序
 */
public class StringDemo4 {

    public String sort(String str){
        if(str != null){
            char[] array = str.toCharArray();
//            Arrays.sort(array);
            for (int i = 0; i < array.length -1; i++) {
                for (int j = 0; j < array.length -1 - i; j++) {
                    if(array[j] > array[j+1]){
                        char temp = array[j];
                        array[j] = array[j+1];
                        array[j+1] = temp;
                    }
                }
            }
            return new String(array);
        }
        return str;
    }

    @Test
    public void test(){

        String str= "jsd;ajdls;aaejwln";
        System.out.println(sort(str));
    }
}
